package com.cg.service.impl;

import com.cg.common.Constants;
import com.cg.service.MessageService;
import com.cg.util.MailUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class MessageServiceImpl implements MessageService {

    @Resource
    private MailUtil mailUtil;
    @Override
    @RabbitListener(queues = Constants.MQ.MAIL_QUEUE)
    public void getMessage(String msg) {
        if (msg == null || !msg.contains(",")) {
            log.error("Invalid message: " + msg);
            return;
        }
        log.info("监听到的消息:{}"+msg);
        String [] arr = msg.split(",");
        String phone = arr[0];
        String code = arr[1];
        //发邮件
        mailUtil.send(phone,"大咪网邮件验证码","大咪网邮件验证码："+code);
    }
}
